<?php
/**
 * 商品控制器
 * 
 * @version $Id: Item.php 312 2012-05-15 12:20:57Z linsir123 $
 */
class controllerItem extends AppController 
{
	/**
	 * 商品明细
	 */
	public function actionInfo()
	{
		$Iid = trim($_GET['iid']);
		if ( ! preg_match("/^[\d]+$/", $Iid)) 
			$this->miss();
			
		///
		$item = M::item()->getInfo($Iid);
		$convert = M::item()->getTaobaoke($Iid);
		if (empty($item) || empty($convert)) 
			$this->miss(empty($item) ? '' : $item['title']);
			
		///
		$category = M::nav()->getOne($item['cid']);
		$shop = M::shop()->getOne($item['nick']);
		$data = M::item()->taobaoke(array('show'=>10,'cid'=>$item['cid'],
			'sort'=>'commissionVolume_desc'));
			
		if (empty($shop['pic_path'])) 
			$shop['pic_path'] = null;
			
		///
		AppView::addJs('jquery.lazyload.js');
		View::display('item');
		View::assignSet(array(
			'iid' => $Iid,
			'item' => $item,
			'convert' => $convert,
			'shop' => $shop, 
			'sideList' => $data[0], 
			'category' => $category, 
			'location' => M::nav()->getLocation($item['cid']), 
		));
	}
	
	/**
	 * 取得淘宝评论列表
	 */
	function actionComment()
	{
		$data = Request::isPost() ? $_POST : $_GET;
		$userId = trim($data['user_id']);
		$Iid = trim($data['num_iid']);
		$page = intval($data['page']);
		!empty($page) or $page = 1;
		
		///
		$url="http://rate.taobao.com/detail_rate.htm?userNumId=".$userId."&auctionNumId=".$Iid."&showContent=2&currentPage=".$page."&ismore=1&siteID=7";
		$content = file_get_contents($url);
		$content = str_replace('TB.detailRate = ', '', $content);
		$content = trim(mb_convert_encoding($content, "utf-8", "gb2312"));
		$list = json_decode($content, true);
		
		/// 页数  分数  打分次数  评价人数
		$totalPage = $list['rateListInfo']['paginator']['items'];
		$totalPage <= 100 or $totalPage = 100;
		if (Request::isPost()) 
			echo $totalPage."@"
				.$list['scoreInfo']['merchandisScore']."@"
				.$list['scoreInfo']['merchandisTotal']."@"
				.$list['rateListInfo']['paginator']['items']."@";
		else 
			echo '<ul id="comment" class="clearfix">';
			
		$domain = App::getRequest()->domain;
		if (is_array($list['rateListInfo']['rateList'])) {
			foreach ($list['rateListInfo']['rateList'] as $v) {
				echo '<li class="clearfix"><div class="left">',$v['rateContent'];
				echo '<br><font color="#999999">[',$v['rateDate'],']</font></div>';
				echo '<div class="right">买家：',$v['displayUserNick'];
				if($v['displayRatePic'] != '') 
					echo '<br><img src="', $domain, 'images/level/', $v['displayRatePic'], '">';
					
				echo '</div></li>';
			}
		}
		
		if (Request::isPost()) {
			$com = App::C('Pagination', '/%d', $page, $totalPage, 8, array(
				'first' =>'第一页', 
				'pre' =>'上一页', 
				'next' =>'下一页'));
			echo "@".$com->display();
		} else 
			echo '</ul>';
	}
}
